import Compile from "./Compile.js";
import {observe} from './observe.js';
import Watcher from "./Watcher.js";
export default class Vue {
    constructor(options) {
        // 把参数options对象存为$options
        this.$options = options || {}
        // 数据
        this._data = options.data || undefined;
        observe(this._data)
        // 数据变为响应式的，这里就是生命周期
        this._initData();
        // 调用默认的watcher
        this._initWatch();
        // this._initComputed();
        // 模板编译
        new Compile(options.el, this)

    }
    _initData() {
        var self = this;
        Object.keys(this._data).forEach(key => {
            Object.defineProperty(self, key,  {
                get() {
                    return self._data[key];
                },
                set(newVal) {
                    self._data[key] = newVal;
                }
            })
        })
    }
    _initComputed() {

    }
    _initWatch() {
        var self = this;
        var watch = this.$options.watch;
        Object.keys(watch).forEach(key => {
            new Watcher(self, key, watch[key])
        })
    }
}